package com.example.back.controller;

import com.example.back.model.Post;
import com.example.back.model.Route;
import com.example.back.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : 贾媛晴
 * @createTime : 2022/5/5 12:25
 */
@RestController
@Api(tags = "PostController")
@CrossOrigin //允许跨域
public class PostController {

    @Autowired
    PostService postService;

    @GetMapping("/Post")
    public List<Post> selectAll(){
        List<Post> postList = this.postService.selectAll();
        return postList;
    }

    // 取出 详情页 的数据
    @GetMapping("/Post_Detail")
    public Post selectDetail( String itemId){
        Post detail=this.postService.selectDetail(itemId);
        return detail;
    }

    @ApiOperation("后台编辑资讯信息")
    @PostMapping("/Edit _Post")
    public int updateArea(int id, String name, String information){
        return this.postService.updatePost(id,name,information);
    }

    @ApiOperation("后台删除资讯信息")
    @GetMapping("/Delete_Post")

    public int deleteArea(int id) {
        return this.postService.deletePost(id);
    }

    @ApiOperation("后台添加资讯信息")
    @GetMapping("/Insert_Post")
    public int insertArea( String name, String information) {
        return this.postService.insertPost(name,information);
    }


}
